package com.cn.web.bean;

import cn.com.allunion.common.page.QueryResult;
import cn.com.allunion.sms.pojo.Userbase;
import com.alibaba.fastjson.annotation.JSONField;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户列表返回结果
 * Created by YangJie on 2016/4/22.
 */
public class UserResult {
    /**
     * 用户Id
     */
    private String userId;
    /**
     * 用户名称
     */
    @JSONField(name = "username")
    private String userName;

    /**
     * 用户密码
     */
    @JSONField(name = "password")
    private String passWord;
    /**
     * 用户类型
     */
    private String userType;

    /**
     * 用户状态
     */
    private Boolean enabled;

    /**
     * 用户创建时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;


    public static UserResult convert(Userbase userbase) {
        if (null == userbase) {
            return null ;
        }
        UserResult userResult = new UserResult() ;
        BeanUtils.copyProperties(userbase, userResult);

        return userResult ;
    }

    public static List<UserResult> convert(List<Userbase> userbaseList) {
        if (CollectionUtils.isEmpty(userbaseList)) {
            return null ;
        }

        List<UserResult> userResultList = new ArrayList<>(userbaseList.size()) ;
        for (Userbase ub : userbaseList) {
            userResultList.add(convert(ub));
        }

        return userResultList ;
    }

    public static QueryResult<UserResult> convert(QueryResult<Userbase> userbaseList) {
        return new QueryResult<>(convert(userbaseList.getResultList()), userbaseList.getTotalRecord()) ;
    }


    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }
}
